package top.honlnk.service.impl.processor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.honlnk.common.utils.SendMailUtil;

import java.time.LocalDateTime;

@Slf4j
@Component
public class AutoSetAccessTokenProcessor {

    @Autowired
    private SendMailUtil sendMailUtil;

    @SuppressWarnings("FieldCanBeLocal")
    private final String subject = "HonlnkSchedule图像识别AccessToken自动更新";
    @SuppressWarnings("FieldCanBeLocal")
    private final String content = "<h1>AccessToken完成了一次自动更新</h1>";

    public void autoSetAccessToken(String[] mailArray, String accessToken) {
        LocalDateTime now = LocalDateTime.now();
        String dateTimeVisual = now.getYear() + "年" + now.getMonthValue() + "月" + now.getDayOfMonth() + "日 " + now.getHour() + ":" + now.getMinute() + ":" + now.getSecond();
        String contentBody = "<div>" +
                "HonlnkSchedule以在" + dateTimeVisual + "自动更新了OCR访问令牌，访问令牌已更新为：" + accessToken +
                "</div>";

        sendMailUtil.sendMail(subject, content + contentBody, mailArray);
    }
}
